package com.tf.temper.swagger;

import java.util.ArrayList;
import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig
{
	@Bean
	public Docket createRestApi()
	{
		List<Parameter> parameterList = new ArrayList<Parameter>();
//		ParameterBuilder tokenBuilder = new ParameterBuilder();
//		List<Parameter> parameterList = new ArrayList<Parameter>();
//		tokenBuilder.name("Authorization")
//        .defaultValue("去其他请求中获取heard中token参数")
//        .description("令牌")
//        .modelRef(new ModelRef("string"))
//        .parameterType("header")
//        .required(true).build();
//		parameterList.add(tokenBuilder.build());

		Docket d = new Docket(DocumentationType.SWAGGER_2).
				apiInfo(apiInfo()).
				select()
				.apis(RequestHandlerSelectors.basePackage("com.tf.temper.controller")).
				paths(PathSelectors.any())
				.build().globalOperationParameters(parameterList);
		
		return d;
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("TFtemper").description("TFtemper swagger文档")
				.termsOfServiceUrl("http://www.ccssoft.com.cn").version("2.0").build();
	}
}